package com.daigoudao.web.common;

import java.util.ArrayList;
import java.util.List;

import com.daigoudao.util.Constants;
import com.daigoudao.web.model.PageInfo;

public class BasePageAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -419694346068353731L;
	/**
	 * 当前页数
	 */
	private int superPage = 1;


	/**
	 * 导航菜单父菜单
	 */
	public int navigation;
	/**
	 * 导航菜单子菜单
	 */
	public int son;
	
	protected String ajaxMsg;

	/**
	 * 总大小
	 */
	private long totalSize;

	/**
	 * 分页记录数
	 */
	private int pageSize = Constants.PAGE_SIZE;

	/**
	 * 总页数
	 */
	private long totalPage;

	private List<PageInfo> pageList;

	public List<PageInfo> getPageList() {
		pageList = new ArrayList<PageInfo>();
		if (superPage == 0) {
			return pageList;
		}
		pageList.add(new PageInfo("1", 1 == superPage));
		int begin = 2;
		if (superPage - 3 > 2) {
			pageList.add(new PageInfo("...", false));
			begin = superPage - 3;
		}
		for (int i = begin; i <= superPage + 4 && i <= totalPage; i++) {
			pageList.add(new PageInfo(i + "", i == superPage));
		}
		if (superPage + 4 < totalPage) {
			pageList.add(new PageInfo("...", false));
		}

		return pageList;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getNavigation() {
		return navigation;
	}

	public void setNavigation(int navigation) {
		this.navigation = navigation;
	}

	public int getSon() {
		return son;
	}

	public void setSon(int son) {
		this.son = son;
	}

	public int getSuperPage() {
		return superPage;
	}

	public void setSuperPage(int superPage) {
		this.superPage = superPage;
	}

	public long getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
		if (totalSize > 0) {
			this.totalPage = (totalSize - 1) / pageSize + 1;
		}
	}

	public long getTotalPage() {
		return totalPage;
	}

	public String getAjaxMsg() {
		return ajaxMsg;
	}

	public void setAjaxMsg(String ajaxMsg) {
		this.ajaxMsg = ajaxMsg;
	}

}